/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.services;

import java.util.HashMap;
import java.util.Map;

/**
 * Class <code>ServiceLocator</code> realize design pattern Service locator.
 * Service locator on request returns the information necessary to perform 
 * a certain task.
 * @author  Maxim Vasilevsky
 * @author  Roman Dyatkovsky
 * @since APUS v0.3
 */
public class ServiceLocator {
    
    private static Map<Class<?>,Object> services = new HashMap<>();
    
    /**
     * Register service in the collection <code>services</code> 
     * @param clazz Class of registered object
     * @param service Directly registered service (object)
     */
    public static void registerService(Class<?> clazz, Object service) {
        services.put(clazz, service);
    }
    
    /**
     * Returns required service
     * @param <ServiceType> Type of service
     * @param clazz Class of object-service
     * @return service
     */
    public static <ServiceType> ServiceType getService(Class<ServiceType> clazz) {
        return (ServiceType) services.get(clazz);
    }
    
}